package org.andcool.audio;

/**
 * @author Joosun
 * @since 2011-5-28
 */
public abstract class BaseAudioEntity implements IAudioEntity
{
	private final IAudioManager<? extends IAudioEntity> mAudioManager;

	protected float mLeftVolume = 1.0f;
	protected float mRightVolume = 1.0f;

	public BaseAudioEntity(final IAudioManager<? extends IAudioEntity> pAudioManager)
	{
		this.mAudioManager = pAudioManager;
	}

	protected IAudioManager<? extends IAudioEntity> getAudioManager()
	{
		return this.mAudioManager;
	}

	public float getActualLeftVolume()
	{
		return this.mLeftVolume * this.getMasterVolume();
	}

	public float getActualRightVolume()
	{
		return this.mRightVolume * this.getMasterVolume();
	}

	protected float getMasterVolume()
	{
		return this.mAudioManager.getMasterVolume();
	}

	@Override
	public float getVolume()
	{
		return (this.mLeftVolume + this.mRightVolume) * 0.5f;
	}

	@Override
	public float getLeftVolume()
	{
		return this.mLeftVolume;
	}

	@Override
	public float getRightVolume()
	{
		return this.mRightVolume;
	}

	@Override
	public final void setVolume(final float pVolume)
	{
		this.setVolume(pVolume, pVolume);
	}

	@Override
	public void setVolume(final float pLeftVolume, final float pRightVolume)
	{
		this.mLeftVolume = pLeftVolume;
		this.mRightVolume = pRightVolume;
	}
}